package com.grj.example;

/**
 * @author ganru
 * @date 2025/10/19 0:45
 */
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;

import java.time.Duration;
import java.util.Collections;
import java.util.Properties;

//public class ConsumerExample {
//    public static void main(String[] args) {
//        Properties props = new Properties();
//        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
//        props.put(ConsumerConfig.GROUP_ID_CONFIG, "demo-group");
//        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
//        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
//        props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
//
//        KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
//        consumer.subscribe(Collections.singletonList("test-topic"));
//
//        System.out.println("✅ Listening for messages...");
//        while (true) {
//            ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(500));
//            for (ConsumerRecord<String, String> record : records) {
//                System.out.printf("Consumed: key=%s value=%s partition=%d offset=%d%n",
//                        record.key(), record.value(), record.partition(), record.offset());
//            }
//        }
//    }
//}
//
//